home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / ast_comp / sql.txt / tpar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-04  |  2.0 KB  |  101 lines

  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include "ddf.h"
  4.  
  5. int     ddf_err;
  6.  
  7. main (argc,argv)
  8. int     argc;
  9. char    *argv[];
  10. {
  11. int     x = 0;
  12. FILE    *fd;
  13. char    s[1024];
  14. DDFRUN  partree;
  15.  
  16.         fd = fopen ("pt_file","w");
  17.         for (printf ("%d>>", x++); getqu (s) && parse (&partree, s) > 0; x++)
  18.         {
  19.                 fwrite (partree.par_buf, partree.buf_len, 1, fd);
  20.                 printf ("%d>>", x);
  21.         }
  22. }
  23.  
  24. /*   old version; no longer used
  25. getq(s)
  26. char    *s;
  27. {
  28.         for(; (*s=getchar()) != EOF && *s != ';' ; s++);
  29.         if(*s == EOF )
  30.                 return 0;
  31.         else
  32.         {
  33.                 *++s = '\0';
  34.                 return 1;
  35.         }
  36. }
  37. */
  38.  
  39. getqu (s)
  40. char    *s;
  41. {
  42. static int      getqtab [3] [5] =
  43.     {
  44.         {0,1,0,(int)'e',0},
  45.         {1,1,2,1,1},
  46.         {2,0,1,1,1}
  47.     };
  48. int     tk;
  49. int     st = 0;
  50.  
  51.         *s = '\0';
  52.         while ( (tk = getqt (s)) != EOF )
  53.         {
  54.                 if (tk == 3 && !st)
  55.                 {
  56.                         return 1;
  57.                 }
  58.                 else
  59.                         st = getqtab[st] [tk];
  60.         }
  61.         return 0;
  62. }
  63.  
  64. getqt (s)
  65. char    *s;
  66. {
  67. int     c;
  68. int     value;
  69. char    buf[256];
  70. char    *sbuf=buf;
  71.  
  72.         if(isspace( (c=getchar()) ))
  73.                 value=0;
  74.         else if( isalpha(c))
  75.         {
  76.                 for(*buf=(islower(c)) ?toupper(c):c; isalpha( (c=getchar()) )
  77. &&
  78.                         c != EOF ; *++sbuf = (islower(c)) ?toupper(c):c);
  79.                 *++sbuf ='\0';
  80.                 if(!strcmp(buf,"END"))
  81.                         value=2;
  82.                 else if(!strcmp(buf,"STORE"))
  83.                         value=1;
  84.                 else
  85.                         value=4;
  86.                 ungetc(c,stdin);
  87.                 strcat(s,buf);
  88.                 return value;
  89.         }
  90.         else if(c==';')
  91.                 value=3;
  92.         else if(c == EOF)
  93.                 value = EOF;
  94.         else
  95.                 value= 4;
  96.         *sbuf = c;
  97.         *++sbuf ='\0';
  98.         strcat(s,buf);
  99.         return value;
  100. }
  101.